package com.itic.hpp.user;

import com.itic.appbase.framework.Base.BaseCode;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.mobile.base.BaseMobile;
import com.itic.system.user.attention.persistence.model.UserAttentionExample;
import com.itic.system.user.attention.service.UserAttentionService;
import com.itic.system.vo.UserVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/hpp/user/attention")
public class UserAttentionInterface extends BaseMobile {

    @Autowired
    private UserAttentionService userAttentionService;

    @RequestMapping(value="/add")
    @ResponseBody
    public Map<String,Object> add(HttpServletRequest request, HttpServletResponse response ){
        Map<String, Object> resultMap = new HashMap<String,Object>();
        String errorCode = PARAM_ERROR_CODE;
        String errorMsg = PARAM_ERROR_MSG;
        try{

        }catch(Exception e){
            errorCode = SERVER_ERROR_CODE;
            errorMsg = SERVER_ERROR_MSG;
            logException("UserAttentionInterface", "add", e.toString(),"添加关注",e);
        }
        resultMap.put(CODE, errorCode);
        resultMap.put(MSG, errorMsg);
        isCrrossDomain(response);
        return resultMap;
    }

    /**
     *  我关注的列表
     * @param request
     * @param response
     * @param userId
     * @return
     */
    @RequestMapping(value="/attentionList")
    @ResponseBody
    public Map<String,Object> attentionList(HttpServletRequest request, HttpServletResponse response,String userId ){
        Map<String, Object> resultMap = new HashMap<String,Object>();
        try{
            if(StringUtils.isNotEmpty(userId)){
                UserAttentionExample example = new UserAttentionExample();
                this.handlePageQueryDefault(request,example);
                resultMap = this.userAttentionService.attentionList(example,userId);
            }else{
                resultMap.put(BaseCode.CODE, BaseCode.PARAM_ERROR_CODE);
                resultMap.put(BaseCode.MSG, BaseCode.PARAM_ERROR_MSG);
            }
        }catch(Exception e){
            resultMap.put(BaseCode.CODE, BaseCode.SERVER_ERROR_CODE);
            resultMap.put(BaseCode.MSG, BaseCode.SERVER_ERROR_MSG);
            logException("UserAttentionInterface", "attentionList", e.toString(),"关注列表",e);
        }
        return resultMap;
    }

    /**
     *  我粉丝的列表
     * @param request
     * @param response
     * @param userId
     * @return
     */
    @RequestMapping(value="/fanList")
    @ResponseBody
    public Map<String,Object> fanList(HttpServletRequest request, HttpServletResponse response,String userId ){
        Map<String, Object> resultMap = new HashMap<String,Object>();
        try{
            if(StringUtils.isNotEmpty(userId)){
                UserAttentionExample example = new UserAttentionExample();
                this.handlePageQueryDefault(request,example);
                resultMap = this.userAttentionService.fanList(example,userId);
            }else{
                resultMap.put(BaseCode.CODE, BaseCode.PARAM_ERROR_CODE);
                resultMap.put(BaseCode.MSG, BaseCode.PARAM_ERROR_MSG);
            }
        }catch(Exception e){
            resultMap.put(BaseCode.CODE, BaseCode.SERVER_ERROR_CODE);
            resultMap.put(BaseCode.MSG, BaseCode.SERVER_ERROR_MSG);
            logException("UserAttentionInterface", "fanList", e.toString(),"粉丝列表",e);
        }
        return resultMap;
    }

}
